#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define uint unsigned int

#define YES cout << "Yes" << '\n'
#define NO cout << "No" << '\n'
#define endl '\n'
const int INF = 1e9;
const int MOD = 998244353;
const int N = 1e5 + 5;
using namespace std;
int gcd(int a, int b)
{
    a = abs(a);
    b = abs(b);
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    if (a < 1000000 && b < 1000000)
    {
        int temp;
        while (b != 0)
        {
            temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }
    int shift = 0;
    while (((a | b) & 1) == 0)
    {
        a >>= 1;
        b >>= 1;
        shift++;
    }
    while ((a & 1) == 0)
        a >>= 1;
    while (b != 0)
    {
        while ((b & 1) == 0)
            b >>= 1;
        if (a > b)
        {
            int temp = a;
            a = b;
            b = temp;
        }
        b = b - a;
    }
    return a << shift;
}
int lcm(int a, int b)
{
    return a / gcd(a, b) * b;
}
/*思考

*/
int s[N] = { 0 };
int p[N] = { 0 };
int q[N] = { 0 };
void solve()
{
    int n = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }

    for (int i = 0; i < n; i++)
    {
        cin >> q[i];
    }

/*
核心代码
k初始为0，随次数递增 也是可选取范围的象征
*/
//k永远指向最远的一个
    for (int i = 0, j = 0, k = 0; k < n; k++) {
        if (p[k] > p[i]) i = k; if (q[k] > q[j]) j = k;
        //如果新来的最大，将i和j指向k;
        if (p[i] != q[j]) {//两个不相等
        //pi更大输出pi组合
            if (p[i] > q[j]) cout<<(s[p[i]] + s[q[k - i]]) % MOD <<' ';
            //qj更大输出qj组合
            else cout<< (s[q[j]] + s[p[k - j]]) % MOD<<' ';
        }
        //如果相等，看qi组的另一个还是pj组的另一个大
        else cout<< (s[p[i]] + s[max(q[k - i], p[k - j])]) % MOD<<' ';
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 0;
    cin >> t;
    s[0] = 1; for (int i = 1; i < N; i++) s[i] = (s[i - 1] << 1) % MOD;
    while (t--)
        solve();
    return 0;
}